<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/24
 * Time: 13:29
 */

namespace app\cli\command;


use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 *
 * Class UpdateInvestAuditStatus
 * @package app\cli\command
 */
class UpdateInvestAuditStatus extends Command
{
    /**
     *
     */
    protected function configure()
    {
        $this->setName('sys_update_invest_audit_status')->setDescription('update invested status ... ');
    }

    /**
     *
     * @param Input $input
     * @param Output $output
     * @return int|null|void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function execute(Input $input, Output $output)
    {

        $db = model('app\\common\\model\\BorrowInvest');

//        strtotime(date('Y-m-d', time())) > ($value['deadline'] - 86400)

        $zero_timestamp = strtotime(date('Y-m-d', time()));
        $list = $db->field('id')->where("(deadline-86400) < {$zero_timestamp}")->select();

        if ($list) {
            foreach ($list as $K => $v) {
                self::updateAuditStatus($v, $db);
            }
        }

        $output->writeln('SUCCESS');
    }

    /**
     * @param $v
     * @param $model
     * @return mixed
     */
    private function updateAuditStatus($v, $model)
    {
        return $model->where(['id' => $v['id']])->update(['audit_status' => 4]);
    }


}